/* CS32 FINAL PROJECT */

package GameEngine;

import GameEngine.GameConstants.Graphic;
import Objects.*;
import GameEngine.GameConstants.Material;
import GameEngine.GameConstants.Modifier;
import GameEngine.GameConstants.Special;
import GameEngine.GameConstants.Thing;
import java.util.List;
import org.dom4j.*;
import org.dom4j.io.SAXReader;
/**
 * This class has only static methods for creating a level data structure from
 * an XML document and a list of player special types.
 * @author mhfowler
 */
public class LevelInitializer {



    /*                XML PROTOCOL
     *
     *      <Level NAME="level1" PLAYERS="4" >
     *          <Object NAME="fan">
     *              <Attr FIELD="xposition" VALUE="10">
     *              <Attr FIELD="yposition" VALUE="3">
     *              <Attr FIELD="material" VALUE="rock">
     *              -
     *              -
     *          -
     *          -
     *          <WallGrid X="100" Y="100">
     *              <GridRow ROW="10011101100..">
     *              <GridRow ROW="10011111111..">
     *              -
     *          <Player XPOS="20" YPOS="20">
     *          -
     *          -
     *      <END>
     *
     * */


     /* This static method is where the hardcode exists that makes a library of
      * objects (enumerations) possible. It takes in a Thing.enumeration which
      * serves as a flag of what kind of object to construct. There can be a many to
      * one mapping of enumerations to classes that extend GameObject. eg Fan might
      * be a class which extends GameObject, and BIGFAN and LITTLEFAN could both be
      * enumerations which cause the constructor to return a fan.
      */
    public static GameObject objectConstructor(Thing obj, Vector m, Vector cen, Vector size) {
        GameObject toReturn = null;
        switch (obj) {
            case BIGFAN:
                toReturn = new Fan(m, cen, size);
                ((Fan) toReturn).setFanPower(4);
                break;
            case LITTLEFAN:
                toReturn = new Fan(m, cen, size);
                ((Fan) toReturn).setFanPower(4);
                break;
            case BIGVACUUM:
                toReturn = new Vacuum(m, cen, size);
                ((Vacuum) toReturn).setVacPower(4);
                break;
            case LITTLEVACUUM:
                toReturn = new Vacuum(m, cen, size);
                ((Vacuum) toReturn).setVacPower(4);
                break;
            case CHOMPERS:
                toReturn = new Chompers(m, cen, size);
                ((Chompers) toReturn).setChompers(100, 5);
                break;
            case SPOUT:
                toReturn = new Spout(m, cen, size);
                ((Spout) toReturn).setSpoutPower(4);
                break;
            case SPAWNPOINT:
                toReturn = new SpawnPoint(cen, size);
                break;
            case GOALPOINT:
                toReturn = new GoalPoint(cen, size);
                break;
            case PLAYER:
                toReturn = new Player(m, cen, size);
                break;
            case WALL:
                toReturn = new Wall(m, cen, size);
                break;
            case WALLBLOCK:
                toReturn = new Wall(m, cen, size);
                break;
            case PORTAL:
                Portal p = new Portal(m, cen, size);
                p.setTeleportTo(m.scaleNew(400));
                toReturn = p;
                break;
            case BIGBOMB:
                Bomb b = new Bomb(m, cen, size);
                b.setStrength(8);
                toReturn = b;
                break;
            case PINKWALL:
                toReturn = new Wall(m, cen, size);
                toReturn.setGraph(Graphic.PINKWALL);
                break;
            case FISH:
                toReturn = new BombDropper(m, cen, size);
                break;
            case SPIKE:
                toReturn = new Spike(m, cen, size);
                break;
            default:
                toReturn = null;
                break;
        }
        return toReturn;
    }



    /* get default size of an object based on enum */
    public static Vector getDefaultSize(Thing t, Vector m) {
      Vector toReturn = null;
        switch (t) {
            case BIGFAN:
                toReturn = new Vector(80,80);
                break;
            case LITTLEFAN:
                toReturn = new Vector(40,40);
                break;
            case BIGVACUUM:
                toReturn = getDefaultSize(Thing.BIGFAN, m);
                break;
            case LITTLEVACUUM:
                toReturn = getDefaultSize(Thing.LITTLEFAN, m);
                break;
            case CHOMPERS:
                toReturn = new Vector(60, 300);
                break;
            case SPOUT:
                toReturn = new Vector(80, 80);
                break;
            case SPAWNPOINT:
                toReturn = new Vector(40,40);
                break;
            case GOALPOINT:
                toReturn = getDefaultSize(Thing.SPAWNPOINT, m);
                break;
            case WALLBLOCK:
                toReturn = new Vector(40,40);
                break;
            case PORTAL:
                toReturn = new Vector(90,90);
                break;
            case BIGBOMB:
                toReturn = new Vector(40,40);
                break;
            case PINKWALL:
                toReturn = new Vector(100,10);
                break;
            case FISH:
                toReturn = new Vector (90,60);
                break;
            case SPIKE:
                toReturn = new Vector(10,40);
                break;
            default:
                toReturn = new Vector (30,30);
                break;
        }
        return toReturn;
    }

}
